package com.googlecode.openauth.web.service.impl;

import static org.junit.Assert.*;

import java.util.UUID;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.googlecode.openauth.web.entity.UserInfo;
import com.googlecode.openauth.web.service.UserService;

public class UserServiceImplTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	// Spring整合MyBatis相关配置文件
	private String[] configFiles = { "applicationContext.xml"};
	// 创建Spring应用上下文
	private ApplicationContext context = new ClassPathXmlApplicationContext(
			configFiles);

	@Test
	public void testUser() {

		// 获取影片业务逻辑对象
		UserService UserService = (UserService) context.getBean("userService");

		try {

			/* 以下为影片业务逻辑操作 */

			// 1、添加一部影片
			UserInfo user = new UserInfo();
			// User.setFname("功夫熊猫2");//设置片名
			// UserService.insertUser(User);//添加影片

			// 2、修改影片信息
			// 先获取待修改的影片信息
			user = UserService.getUserById(1);// 12为功夫熊猫2的影片编号
			// 修改影片名称
			// User.setFname("功夫熊猫3");
			// 修改操作
			// UserService.updateUser(User);

			// 3、删除"功夫熊猫3"，其编号为12
			// UserService.deleteUser(12);

			// List<User> UserList = UserService.getAllUser();

			// 4、显示所有电影信息
			// for(User UserObj : UserList){

			user.setAddress("mode111");
			UserService.updateUser(user);
			
			
			UserInfo newUser = new UserInfo();
			int userId = 2;
			newUser.setUserId(userId);
			UUID uuid = UUID.randomUUID();
			newUser.setUuid(uuid.toString());
			newUser.setPassword("werqwerqwre");
			
			newUser.setUsername("insertName");
			
			UserService.insertUser(newUser);
			
			UserService.deleteUser(userId);
			
			
			 System.out.println("电影ID：" + user.getUsername() + " 电影名："+user.getAddress() );
			 //+
			// UserObj.getFname());
			// }

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
	
	@Test
	public void testInsertUser() {
		fail("Not yet implemented");
	}

	@Test
	public void testDeleteUser() {
		fail("Not yet implemented");
	}

	@Test
	public void testUpdateUser() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetUserById() {
		fail("Not yet implemented");
	}

	@Test
	public void testGetAllUser() {
		fail("Not yet implemented");
	}

}
